package com.ruoyi.job.task;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;

import com.ruoyi.job.domain.YqgBarBills;
import com.ruoyi.job.service.IYqgBarBillsService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import com.ruoyi.library.api.RemoteLibraryService;
import com.ruoyi.library.api.domain.YhMsgInner;
import java.util.ArrayList;

import static com.ruoyi.common.security.utils.SecurityUtils.getLoginUser;
//然后注入


@Component("MsgTask")
public class SendMsgTask
{
    @Autowired
    private IYqgBarBillsService yqgBarBillsService;
    @Autowired
    private RemoteLibraryService remoteLibraryService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        /*LoginUser loginUser = getLoginUser();
        System.out.println(loginUser.getSysUser());
        SysUser sysUser = loginUser.getSysUser();
        System.out.println(sysUser);*/
        //写自己的消息体
        YhMsgInner msg=new YhMsgInner();
        YqgBarBills yqgBarBills=new YqgBarBills();
        yqgBarBills.setHandState("1");
        List<YqgBarBills> list = yqgBarBillsService.selectYqgBarBillsList(yqgBarBills);
        for(int i=0;i<list.size();i++){

            Date retime= DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",list.get(i).getOpeningTime()) ;
            LocalDateTime Record= LocalDateTime.ofInstant(retime.toInstant(), ZoneId.systemDefault());
            LocalDateTime newDateTime = Record.plusHours(22);
            LocalDateTime currentDateTime = LocalDateTime.now();

            if(currentDateTime.isAfter(newDateTime)){
                msg.setMsgTitle("门票到期提醒");
                msg.setMsgContent("手牌号"+list.get(i).getHandBrand()+"的顾客，门票时间不足两小时，请及时通知顾客。");
                msg.setSendUserName("admin");//这里写发送者名字，填用户名就行，必填
                msg.setNote1("管理员");//这里填写发送者的昵称，对表的user表的nick_name，必填
                msg.setNote2("这里填写你业务的相对url，如/notice/noticelist，必填");
                List<String> receiveNames = new ArrayList<>();
                // 这里根据需要添加你要通知的用户名 可以有一个或多个 也就是user表的userName字段
                receiveNames.add("admin");
                //调用服务
                remoteLibraryService.PushMag(msg,receiveNames);

            }

        }

    }
}
//定时器
/*
@Component
public class SendMsgTask {
    @Autowired
    private IYqgBarBillsService yqgBarBillsService;
    YqgBarBills yqgBarBills=new YqgBarBills();
    @Scheduled(fixedRate = 60 * 60 * 1000) // 每十分钟运行一次
    public void sendMsg() {
        System.out.println("进来了");

    }

}*/
